import { esaxios } from '@/utils/EsAjax';

/**
* DltApi
* 尽量采用 Resetful 资源路由格式（包括 index, read, save, update, delete）。
*/
class DltApi {
    urls = {
        index: '/dlt/order-list',
        read: '/dlt/order-detail',
        save: '/dlt/order-save',
    }
    constructor(axios) {
        this.axios = axios;
    }

    async option() {
        return await this.axios.get(this.urls.option);
    }

    async index(params) {
        return await this.axios.get(this.urls.index, { params });
    }

    async read(id) {
        return await this.axios.get(`${this.urls.read}?n=${id}`);
    }

    async save(data, isUpdate = false) {
        if (isUpdate) {
            return await this.update(data.id, data);
        }
        return await this.axios.post(this.urls.save, data);
    }

    async update(id, data) {
        return await this.axios.put(`${this.urls.update}/${id}`, data);
    }

    async delete(id) {
        return await this.axios.delete(this.urls.delete, { param: { id } })
    }

    async aichoose(provider) {
        return await this.axios.get(`${this.urls.aichoose}?provider=${provider}`);
    }
}

export default new DltApi(esaxios);